<template>
  <div>
    <template>
      <div>
        <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
          <el-breadcrumb-item :to="{ path: '/' }"><i class="el-icon-s-promotion"></i> 新增员工列表</el-breadcrumb-item>
        </el-breadcrumb>

        <el-divider></el-divider>

        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

          <el-form-item label="员工id" prop="employeeId"><el-input v-model="ruleForm.employeeId"></el-input></el-form-item>

          <el-form-item label="员工姓名" prop="name"><el-input v-model="ruleForm.name"></el-input></el-form-item>

          <el-form-item label="员工性别" prop="gender"><el-input v-model="ruleForm.gender"></el-input></el-form-item>

          <el-form-item label="出生日期" prop="dateOfBirth"><el-input v-model="ruleForm.dateOfBirth"></el-input></el-form-item>

          <el-form-item label="部门Id" prop="departmentId"><el-input v-model="ruleForm.departmentId"></el-input></el-form-item>

          <el-form-item label="职位" prop="position"><el-input v-model="ruleForm.position"></el-input></el-form-item>

          <el-form-item label="入职日期" prop="hireDate"><el-input v-model="ruleForm.hireDate"></el-input></el-form-item>

          <el-form-item label="工资" prop="salary"><el-input v-model="ruleForm.salary"></el-input></el-form-item>

          <el-form-item label="联系电话" prop="contactNumbe"><el-input v-model="ruleForm.contactNumber"></el-input></el-form-item>

          <el-form-item label="地址" prop="email"><el-input v-model="ruleForm.email"></el-input></el-form-item><el-form-item>

            <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </template>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        employeeId: '',
        name: '',
        gender: '',
        dateOfBirth: '',
        department:'',
        position: '',
        hiredate: '',
        salary: '',
        contactnumber:'',
        email: '',
        enable: 0,
        isDisplay: ''
      },
      rules: {
        departmentId: [
          {required: true, message: '员工id', trigger: 'blur'}
        ],
        name: [
          {required: true, message: '请输入员工名称', trigger: 'blur'},
          {
            pattern: /^(?:[\u4e00-\u9fa5]{1,5}|[\u4e00-\u9fa5a-zA-Z\s]{2,12})$/,
            message: '类别名称只能是1~5长度的汉字，或者2~12个长度的由英文、汉字、空格组成的名称！',
            trigger: 'blur'
          }
        ],
        gender: [
          {required: true, message: '性别', trigger: 'blur'}
        ],
        dateOfBirth: [
          {required: true, message: '出生日期', trigger: 'blur'}
        ],
        department: [
          {required: true, message: '部门', trigger: 'blur'}
        ],
        position: [
          {required: true, message: '职位', trigger: 'blur'}
        ],

        hiredate: [
          {required: true, message: '请输入日期', trigger: 'blur'}
        ],
        salary: [
          {required: true, message: '请输入工资', trigger: 'blur'},
        ],
        contactnumber: [
          {required: true, message: '联系电话', trigger: 'blur'},
        ],
        email: [
          {required: true, message: '地址', trigger: 'blur'},
        ],
      }
    };
  },
  methods: {
    submitForm() {
      let url = 'http://localhost:9980/categories/add-new';
      console.log('url = ' + url);
      this.axios.post(url, this.ruleForm).then((response) => {
        if (response.data.state == 20000) {
          alert('添加员工成功');
        } else {
          this.$message.error(response.data.message);
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>